This code implements a "rubber band" marquee select rect with very smooth drawing in a manner similar to the Mac Finder.
Unlimited use is hereby granted without restriction. However, the author would appreciate credit if possible.
Comments, questions, bugs, etc. should be sent to me:
jordanz@altura.com
* * *
History
The Mac System 7 Finder’s marquee selection rects draw in a very smooth manner that makes it appear as though offscreen bitmaps are used. However, for the first time from this special TV offer, you too can do this at home for fun and profit.
The Problem
The quick solution to marquee selection rects is a few lines of code ala:
void easy_marquee(Point pin_pt, Point new_pt, Rect* old_marquee_r_ptr)
{
PenState pen_state;
GetPenState(&pen_state);
PenMode(patXor);
PenPat(&qd.gray);
FrameRect(old_marquee_r_ptr);
Pt2Rect(pin_pt, new_pt, old_marquee_r_ptr);
FrameRect(old_marquee_r_ptr);
}
While this is easy, it has the problem of a lot of flashing. This is because there are areas in common between the old marquee rect and the new one. In addition, using Pt2Rect causes the pin point to move around, which is bad.
The Solution
The Finder Marquee code only draws the areas that need to be redrawn. Your flashing days are over! In addition, while supplies last, it correctly calculates the marquee rect instead of using Pt2Rect.